﻿using System;
using System.IO;
using System.Collections.Generic;

using System.Diagnostics;

namespace EagleJournalBE.Util
{
    public enum LoggingType
    {
        INFO,
        WARN,
        STOP
    }

    public static class Logger
    {
        private static  int         tabStack    = 0;
        private static  TextWriter  tWriter     = null;

        public static void WriteInfo    (LoggingType logType, object parent, string message)
        {
            if (tWriter == null)
            {
                try
                {
                    string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format("{0}-{1}.txt", DateTime.Now.ToBinary(), DateTime.Now.ToFileTime()));

                    tWriter = new StreamWriter(new FileStream(path, FileMode.Create));
                }
                catch (IOException ioex)
                {

                }
            }

            if (parent == null)
                return;

            string logMessage = string.Format("{0}: {1}", parent.GetType().Name, message);

            Debug.  WriteLine(logMessage, logType.ToString());
            tWriter.WriteLine(string.Format("{0}: {1}", logType.ToString(), logMessage));

            tWriter.Flush();
        }

        public static void PushTab      ()
        {
            tabStack++;
        }
        public static void PopTab       ()
        {
            tabStack--;

            if (tabStack == -1)
                tabStack = 0;
        }
    }
}
